<?php

require_once($AppUI->getSystemClass('dp'));

class CProject_files extends CDpObject{

   /** sql
    * DROP TABLE IF EXISTS `project_files`;
    * CREATE TABLE `project_files` (
                   `pfile_id` int(9) NOT NULL auto_increment,
                   `pfile_project` int(9) NOT NULL,
                   `pfile_name` varchar(255) character set utf8 collate utf8_bin NOT NULL default '',
                   `pfile_path` varchar(255) character set utf8 collate utf8_bin default '',
                   `pfile_type` varchar(16) character set utf8 collate utf8_bin default NULL,
                   `pfile_size` varchar(32) collate latin1_general_ci default '0',
                   `pfile_date` datetime default '0000-00-00 00:00:00',
                   `pfile_version` varchar(32) character set utf8 collate utf8_bin default NULL,
                   `pfile_description` varchar(1024) character set utf8 collate utf8_bin default NULL,
                   PRIMARY KEY  (`pfile_id`)
                 ) ENGINE=MyISAM AUTO_INCREMENT=11
    */
	var $pfile_id = NULL;
	var $pfile_project = NULL;
	var $pfile_name = NULL;
	var $pfile_path = NULL;
	var $pfile_type = NULL;
	var $pfile_size = NULL;
	var $pfile_date = NULL;
	var $pfile_description = NULL;
	var $pfile_version = NULL;

    function CProject_files(){
    	$this->CDpObject('project_files', 'pfile_id');
    }

    // overload the delete method of the parent class for adaptation for quotations's needs
	function deleteById($id){
		$sql = 'DELETE FROM project_files WHERE pfile_id = ' . $id;
		// Delete file
		if (!db_exec($sql)) {
			return db_error();
		} else {
			return NULL;
		}
	}

	function getFileById($uid, $id){
		$q  = new DBQuery;
		$q->addTable('project_files');
		$q->addWhere('pfile_id = ' . $id);
		$q->addQuery('*');
		$sql = $q->prepare();
		$q->clear();
		return db_loadList($sql);
	}

	function getListByProjectId($uid, $id){
		$q  = new DBQuery;
		$q->addTable('project_files');
		$q->addWhere('pfile_project = ' . $id);
		$q->addQuery('*');
		$sql = $q->prepare();
		$q->clear();
		return db_loadList($sql);
	}
}
?>